package com.uinnova.websocketstu.controller;

import com.uinnova.websocketstu.websocket.MyWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    private MyWebSocket myWebSocket;


    @RequestMapping(value = "/socket")
    public String socket(){
        return "/socket";
    }

    @RequestMapping(value = "/topic/{message}")
    public String topic(@PathVariable String message) throws IOException {
        Map<String, String> returnMap = new HashMap<String, String>();
        returnMap.put("message",message);
        myWebSocket.sendInfo(message);
        return "/success";
    }
}
